package com.yanqu.road.server.cmd.player;

import com.yanqu.road.logic.pb.SignPb;
import com.yanqu.road.entity.player.UserSign;
import com.yanqu.road.pb.sign.SignProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.sign.SignModule;
import com.yanqu.road.server.manger.ConfigMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

@Cmd(code= Protocol.S_SIGN_IN, desc = "签到")
public class SignInCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(SignModule.class).userSign();
    }

    @Override
    public void sendData(GamePlayer player) {
        SignProto.GetSignRespMsg.Builder respMsg = SignProto.GetSignRespMsg.newBuilder();
        respMsg.setRet(ret);
        if(0 == ret){
            UserSign userSign = player.getModule(SignModule.class).getUserSign();
            SignProto.SignDataMsg.Builder signMsg = SignPb.parseSignDataMsg(userSign, ConfigMgr.getSignRewardMap().size());
            if(null != signMsg){
                respMsg.setSignData(signMsg);
            }
        }
        player.sendPacket(Protocol.U_SIGN_IN, respMsg);
    }
}
